<%@ page language="java" contentType="text/html; charset=windows-1255" pageEncoding="windows-1255"%>
<%@ include file="admin_Header.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Add Supermarket</title>
</head>
<body>
<%
	if ((request.getParameter("supermarketName") != null) &&
	    (request.getParameter("supermarketBranch") != null) &&
	    (request.getParameter("supermarketLatitude") != null) &&
	    (request.getParameter("supermarketLongitude") != null))
	{
		out.println("Adding supermarket " + request.getParameter("supermarketName"));
		try
		{
			String supermarketName = request.getParameter("supermarketName");
			String supermarketBranch = request.getParameter("supermarketBranch");
			Double supermarketLatitude = Double.parseDouble(request.getParameter("supermarketLatitude"));
			Double supermarketLongitude	= Double.parseDouble(request.getParameter("supermarketLongitude"));
			Supermarket supermarket = new Supermarket();
			supermarket.setSupermarketName(supermarketName);
			supermarket.setSupermarketBranch(supermarketBranch);
			supermarket.setSupermarketLocationLatitude(supermarketLatitude);
			supermarket.setSupermarketLocationLongitude(supermarketLongitude);
			iproducts.AddSupermarket(supermarket);
			Supermarket verifySupermarket = iproducts.FindSupermarket(supermarket.getSupermarketName(), supermarket.getSupermarketBranch(), supermarket.getSupermarketLocationLatitude(), supermarket.getSupermarketLocationLongitude());
			if ((verifySupermarket.getSupermarketName().equals(supermarketName)) &&
				(verifySupermarket.getSupermarketBranch().equals(supermarketBranch)) &&
				(verifySupermarket.getSupermarketLocationLatitude().equals(supermarketLatitude)) &&
				(verifySupermarket.getSupermarketLocationLongitude().equals(supermarketLongitude)))
			{
				out.println("\nSupermarket added successfully");
			}
			else
			{
				out.println("\nSomething went wrong, please check");
			}
		}
		catch(Exception e)
		{
			throw new Exception("Error in connecting to database, please contact your administrator");
		}
	}
%>
<center>
	<h1>Product Compare Application</h1>
	<button id="List" onclick="window.location.href='admin_ListProducts.jsp'">Get Product List</button>
	<button id="AddProduct" onclick="window.location.href='admin_AddProduct.jsp'">Add New Product</button>
	<button id="AddSuperMarket" onclick="window.location.href='admin_AddSupermarket.jsp'">Add New SuperMarket</button>
	<button id="ManageSuperMarket" onclick="window.location.href='admin_ManageSupermarket.jsp'">Manage Supermarket</button>
	<button id="DeleteProduct" onclick="window.location.href='admin_DeleteProduct.jsp'">Delete Product</button>
	<button id="DeleteSupermarket" onclick="window.location.href='admin_DeleteSupermarket.jsp'">Delete Supermarket</button>
</center>
<center>
<br><br>
<form action="admin_AddSupermarket.jsp" method="post">
<table border=1>
	<tr>
		<th colspan=2>Add Supermarket</th>
		<tr>
			<td>
				<label>Supermarket Name</label>
			</td>
			<td> 
				<input type="Text" name="supermarketName">	
			</td> 
		</tr>
		<tr>
			<td>
				<label>Supermarket Branch</label>
			</td>
			<td> 
				<input type="Text" name="supermarketBranch">	
			</td> 
		</tr>
		<tr>
			<td>
				<label>Supermarket Latitude</label>
			</td>
			<td>
				<input type="Text" name="supermarketLatitude">	
			</td> 
		</tr>
		<tr>	
			<td>
				<label>Supermarket Longitude</label>
			</td>
			<td>
				<input type="Text" name="supermarketLongitude">	
			</td>
		</tr>
		<tr>
			<td colspan=2 align="center">
				<button type="submit">Submit</button>
			</td>
		</tr>
</table>
</form>
</center>
</body>
</html>